<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body></body>
</html>
<script>
    const str = `
        <h1>这里是第一个标题</h1>
        <h2>这里是第二个标题</h2>
        <h3>这里是第三个标题</h3>
        <h4>这里是第四个标题</h4>
    `;
    const reg = /<(h[1-6])>([\s\S]*)<\/\1>/gi;
    const res = str.replace(reg, `<div class="title">$2</div>`);
    console.log(res);
    console.dir(reg.exec(str));
</script>
